package com.wanczy.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanczy.pojo.MenuTable;
import com.wanczy.service.MenuOpService;
import com.wanczy.service.impl.MenuOpServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * Servlet implementation class MenuQueryServlet
 */
@WebServlet("/servlet/MenuQueryServlet")
public class MenuQueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();// ȡ��out����
		
		String menuName = request.getParameter("menuName");
		MenuOpService service = new MenuOpServiceImpl();
		List<MenuTable> list = service.findByMenuName(menuName,1);
		JSONArray jsonA = new JSONArray();
		for (MenuTable menuTable : list) {
			JSONObject jsonO = new JSONObject();
			jsonO.put("menuId", menuTable.getMenu_id());
			jsonO.put("menuName", menuTable.getMenu_name());
			jsonO.put("menuDescribe", menuTable.getMenu_describe());
			if(menuTable.getMenu_state() == 1) {
				jsonO.put("menuState", "start");
			}else {
				jsonO.put("menuState", "stop");
			}
			jsonO.put("menuUrl", menuTable.getMenu_url());
			jsonO.put("menuLevel", menuTable.getMenu_level());
			jsonA.add(jsonO);
		}
		out.print(jsonA.toString());
		out.close();
	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
